#include "direction.h"

struct direction
{
  int x;
  int y;
	vers v;
};

direction DIRnew()
{
	direction d = malloc(sizeof(struct direction));
	d->x = 0;
	d->y = 0;
	d->v = NONE;
	return d;
}

direction DIRcopy(direction d)
{
	direction nd = DIRnew();
	nd->x = d->x;
	nd->y = d->y;
	nd->v = d->v;
	return nd;
}

void DIRfree(direction d)
{
	if( d != NULL )
		free(d);
}

int DIRgetX(direction d) { return d->x; }
int DIRgetY(direction d) { return d->y; }
int DIRgetV(direction d) { return d->v; }

void DIRsetX(direction d, int x) { d->x = x; }
void DIRsetY(direction d, int y) { d->y = y; }
void DIRsetV(direction d, int v) { d->v = v; }

void DIRsetDir(direction d, vers v)
{
	d->v = v;
	switch(v)
	{
		case UP:
			d->x = UP_X;
			d->y = UP_Y;
			break;
		case DOWN:
			d->x = DOWN_X;
			d->y = DOWN_Y;
			break;
		case LEFT:
			d->x = LEFT_X;
			d->y = LEFT_Y;
			break;
		case RIGHT:
			d->x = RIGHT_X;
			d->y = RIGHT_Y;
			break;
		case NONE:
			d->x = 0;
			d->y = 0;
			break;
	}
}
